<template>
  <!-- 发票管理列表页 -->
  <div>
    <div class="shareContainer" ref="shareContainer" v-show="checkType === ''">
      <!-- <el-tabs
        class="tab"
        type="border-card"
        v-model="activeName"
        @tab-click="displayOrdersData()"
      >
        <el-tab-pane label="待申请" name="0"> </el-tab-pane>
        <el-tab-pane label="已申请" name="1"> </el-tab-pane>
        <el-tab-pane label="待开票" name="2"> </el-tab-pane>
        <el-tab-pane label="已开票" name="3"> </el-tab-pane>
        <el-tab-pane label="已作废" name="4"> </el-tab-pane>
      </el-tabs> -->
      <div class="content-wrapper">
        <div class="actions" style="padding-bottom: 10px">
          <div class="left">
            <el-button
              plain
              @click="applyForReceipt"
              type="primary"
              v-if="activeName === '0'"
              data-tracker="P51-3"
              >申请开票</el-button
            >
            <el-button
              plain
              @click="invoice_apply_delete"
              type="primary"
              v-if="activeName === '0'"
              data-tracker="P51-3"
              >删除</el-button
            >
            <!-- <el-button plain @click="invoice_apply_delete" type="primary" v-show="activeName === '0'"
            data-tracker="P51-3">发起审核</el-button> -->
            <el-button
              @click="toAdoptReceipt"
              plain
              type="primary"
              v-if="activeName === '2'"
              data-tracker="P51-6"
              >开票</el-button
            >
            <el-button
              @click="deriveExprot"
              plain
              type="primary"
              data-tracker="P51-6"
              >导出</el-button
            >
            <el-button
              plain
              type="primary"
              v-if="activeName === '3'"
              @click="abolishReceipt"
              data-tracker="P51-8"
              >作废</el-button
            >
          </div>
          <div class="right" style="display: flex">
            <el-button
              type="primary"
              size="mini"
              @click="resultClickFn"
              style="margin: 0px 10px 0px 0px"
              >重置
            </el-button>
            <SettinUp
              :settype="headerId"
              :objSettinUpdata="objSettinUp"
              :key="activeName"
            ></SettinUp>
          </div>
        </div>
        <!-- 表格 -->
        <div class="table" v-if="header_data_list.length > 0" :key="activeName">
          <TableHeader
            ref="TableHeaderList"
            :header_data_list="header_data_list"
            :HeaderData="HeaderData"
            :propMap="propMap"
            :redact="''"
            :particulars="''"
            :objheader="objheader"
            @orderIdNumsEvent="handleDeleteType"
            :operation_type="3"
          >
            <template #operation="{ scope }">
              <el-button
                type="text"
                plain
                size="mini"
                @click="handleClickDetail(scope.row)"
                v-if="activeName != '3'"
                >详情
              </el-button>
              <el-button
                v-if="activeName === '3'"
                data-tracker="P5-5"
                type="text"
                plain
                size="mini"
                @click="toAdoptReceiptDetail(scope.row)"
                >开票详情
              </el-button>
              <el-button
                type="text"
                plain
                size="mini"
                @click="handleClickDetail(scope.row)"
                v-if="activeName == '3'"
              >
                开票申请详情
              </el-button>
              <el-button
                v-if="activeName === '0'"
                data-tracker="P5-5"
                type="text"
                plain
                size="mini"
                @click="handleClickEdit(scope.row)"
                >编辑
              </el-button>
            </template>
          </TableHeader>
        </div>
        <div class="actions" style="padding-top: 10px; width: 100%">
          <div class="left"></div>
          <div class="right">
            <el-pagination
              small
              background
              :current-page="paginations.pageIndex"
              :page-sizes="paginations.pageSizes"
              :page-size="paginations.pageSize"
              :layout="paginations.layout"
              :total="paginations.total"
              @size-change="handleSizeChange1"
              @current-change="handleCurrentChange1"
            />
          </div>
        </div>
        <el-dialog
          width="600px"
          title="开票"
          :visible.sync="showReceiptReturn"
          :close-on-click-modal="false"
        >
          <el-form
            label-position="right"
            label-width="120px"
            :rules="rules"
            :model="receiptReturnData"
            ref="formList"
          >
            <el-form-item
              label="开票时间"
              style="width: 520px"
              prop="make_out_invoice_time"
            >
              <el-date-picker
                :disabled="receiptDisable"
                :value="new Date()"
                type="datetime"
                :picker-options="pickerOptions"
                value-format="timestamp"
                v-model="receiptReturnData.make_out_invoice_time"
              >
              </el-date-picker>
            </el-form-item>
            <el-form-item
              label="实际开票金额"
              prop="actual_invoice_amount"
              style="width: 520px"
            >
              <el-input
                :disabled="receiptDisable"
                style="width: 220px"
                v-model="receiptReturnData.actual_invoice_amount"
                type="number"
              ></el-input>
            </el-form-item>
            <el-form-item label="电子发票附件"   prop="invoice_annex" style="width: 520px">
              <UploadLink
                :files.sync="receiptReturnData.invoice_annex"
              ></UploadLink>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button
              @click="
                showReceiptReturn = false;
                receiptDisable = false;
              "
              >取 消</el-button
            >
            <el-button
              type="primary"
              @click="receiptSubmit('formList')"
              v-if="!receiptDisable"
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </div>
    </div>
    <div class="innerVisible">
      <el-dialog
        title="申请开票"
        :visible.sync="dialogTableVisible"
        width="80%"
      >
        <div class="innerVisible_header">
          <el-form ref="form" :model="query_customer" :inline="true">
            <el-form-item label="对账单号" size="mini" style="width: 270px">
              <el-input
                v-model="query_customer.account_no"
                style="width: 200px"
              ></el-input>
            </el-form-item>
            <el-form-item label="客户名称" size="mini" style="width: 270px">
              <el-select
                filterable
                @focus="getCustomerList"
                v-model="query_customer.account_customer_id"
                style="width: 200px"
              >
                <el-option
                  v-for="customer in customerList"
                  :key="customer.id"
                  :label="customer.name"
                  :value="customer.id + ''"
                />
              </el-select>
            </el-form-item>
            <el-form-item
              label="创建对账单时间"
              size="mini"
              style="width: 340px"
            >
              <el-date-picker
                v-model="query_customer.creationTimee"
                type="daterange"
                value-format="timestamp"
                align="right"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
                :default-time="['00:00:00', '23:59:59']"
                style="width: 230px"
              />
            </el-form-item>
            <el-form-item size="mini">
              <el-button
                type="primary"
                data-tracker="P51-1"
                icon="el-icon-search"
                @click="query_customer_Orders"
                >查询</el-button
              >
              <el-button
                plain
                icon="el-icon-refresh-left"
                data-tracker="P51-2"
                @click="query_customer_reset"
                >重置</el-button
              >
            </el-form-item>
          </el-form>
        </div>
        <div></div>
        <div class="innerVisible_pagin">
          <div>
            <el-pagination
              @size-change="innerVisible_handle"
              @current-change="innerVisible_Change"
              :current-page="currentPage4"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="query_customer.page_size"
              layout="total, sizes, prev, pager, next, jumper"
              :total="alltotal"
            >
            </el-pagination>
          </div>
        </div>
        <div class="innerVisible_table">
          <el-table
            :data="ordersList"
            border
            style="width: 120%"
            @selection-change="innerVisible_tionChange"
          >
            <el-table-column type="selection" width="45"> </el-table-column>
            <el-table-column
              prop=""
              label="序号"
              width="50"
              type="index"
            ></el-table-column>
            <el-table-column prop="account_no" label="对账单号" width="180">
              <template slot-scope="scope">
                <div
                  style="color: blue; cursor: pointer"
                  @click="StatementNumber(scope.row.id)"
                >
                  {{ scope.row.account_no }}
                </div>
              </template>
            </el-table-column>
            <el-table-column
              prop="account_customer_name"
              label="承运商名称"
              width="180"
            >
            </el-table-column>
            <el-table-column prop="is_adjust" label="是否调账">
              <template slot-scope="scope">
                {{ scope.row.is_adjust === "1" ? "是" : "否" }}
              </template>
            </el-table-column>
            <el-table-column prop="ar_status" label="审批状态" width="240">
              <template slot-scope="scope">
                {{
                  ["待审批", "审批中", "待开票", "已开票", "已收款"][
                    scope.row.ar_status
                  ]
                }}
              </template>
            </el-table-column>
            <el-table-column prop="now_price" label="对账金额" width="240">
            </el-table-column>
            <el-table-column prop="creator" label="创建人" width="240">
            </el-table-column>
            <el-table-column prop="type" label="创建人类型" width="240">
              <template slot-scope="scope">
                {{ scope.row.type === "0" ? "发货客户" : "承运商" }}
              </template>
            </el-table-column>
            <el-table-column
              prop="create_time"
              label="创建对账单时间"
              width="240"
            >
              <template slot-scope="scope">
                {{
                  new Date(Number(scope.row.create_time) * 1000)
                    .toLocaleString()
                    .replace(/:\d{1,2}$/, " ")
                }}
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="innerVisible_button">
          <el-button type="primary" plain @click="NewStatement()"
            >下一步</el-button
          >
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { timestamp10 } from "@/utils/mUtils";
import UploadLink from "@/components/uploadFile/uploadLink.vue";
import pagination from "@/components/pagination";
import receiptDialog from "./receiptDialog.vue";
import { reqHandlersList } from "@/api/waybill";
import { uploading } from "@/page/material/common/common";
import customerCheckDetail from "../customerlist/customerCheckDetail.vue";
import carrierCheckDetail from "../customerlist/carrierCheckDetail.vue";
import {
  invoice_apply_detail,
  invoice_apply_list_export,
} from "@/api/paymentrequest";
import { getCustomerCheckedList } from "@/api/finance";
import {
  reqReceiptList, //已申请，待开，已开，作废发票列表
  reqReceiptReturnList, //待申请发票列表
  reqAuditReceipt, //审核发票
  reqAdoptReceipt, //开票
  reqCancelReceipt, //作废、取消开票
  reqReceiptBookList, //我方发票主体
  reqRedFlushReceipt, //红冲
  invoice_apply_send_revieww, //发送审核
  finance_invoice_apply_delete, //删除发票
} from "@/api/finance";
import TableHeader from "@/page/orderform/components/TableHeader/tableheader.vue";
import SettinUp from "@/page/orderform/components/settingUp/settingUp.vue";
export default {
  name: "receiptManage",
  filters: {
    afterTime(value) {
      switch (value) {
        case "0":
          return "其它";
        case "1":
          return "承运商应付申请";
        case "2":
          return "报销申请";
        case "3":
          return "备用金申请";
        case "4":
          return "付款申请";
      }
    },
    statusList(value) {
      switch (value) {
        case "1":
          return "专用发票";
        case "2":
          return "普通发票";
      }
    },
  },
  data() {
    return {
      type: "", //0客户  1承运商
      invoice_id: "", //发票的id
      activeName: "0", //tabs切换
      customerList: [], //客户名称
      bigAreaList: [], //区域的列表
      salesList: [], //销售列表
      company_invoice_book_list: [], //我方发票主体的列表
      creatorList: [], //操作人
      checkSearchData: {
        branch_id: "",
        apply_no: "",
        customer_id: "",
        user_id: "",
      }, //对账单维度查询条件
      receiptSearchData: {
        account_no: "",
        customer_id: "",
        status: "",
        company_invoice_body_id: "",
        last_editor_id: "",
      }, //发票维度查询条件
      pickerOptions: {
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      rules: {
        make_out_invoice_time: [
          { required: true, message: "请选择开票时间", trigger: "change" },
        ],
        actual_invoice_amount: [
          { required: true, message: "请输入开票金额", trigger: "change" },
        ],
        invoice_annex: [
          { required: true, message: "请上传电子发票附件", trigger: "change" },
        ],
      },
      pageNum1: 1, //目前在第几页
      totalListNum1: 10, //列表总数
      pageSize1: 20, //一页多少条
      pageNum2: 1, //目前在第几页
      totalListNum2: 10, //列表总数
      pageSize2: 20, //一页多少条
      tableData1: [],
      tableData2: [],
      showReceiptReturn: false, //开票的dialog
      receiptDisable: false, //开票不可编辑
      receiptReturnData: {
        id: "", //发票id
        make_out_invoice_time: new Date().getTime(),
        actual_invoice_amount: "", //开票金额
        invoice_annex: [], //附件
      },
      fileList: [], //附件列表
      dialogImageVisible: false, //附件预览
      dialogImageUrl: "", //预览的图片路径
      selectedOrders: [], //选中的列表单子的id
      selectedDetails: [], //选中的列表单子的详细信息
      operationType: false, //true是查看详情,false是修改
      // ========================
      dialogTableVisible: false,
      query_customer: {
        branch_id: "",
        account_no: "",
        account_customer_id: "",
        account_status: "2", // 0待对账 1对账中 2对账通过 3对账异常
        ar_status: "0", //  申请开票时
        user_id: "", // 所属销售id
        is_deleted: "", // 获取已取消列表用 is_deleted="1"
        start_time: "",
        end_time: "",
        creationTimee: [],
        page: "1",
        page_size: "10",
      },
      ordersList: [],
      currentPage4: 1,
      alltotal: 0,
      idlist: [],
      paginations: {
        pageIndex: 1, // 当前位于哪页
        pageSize: 20, // 1页显示多少条
        pageSizes: [10, 20, 50, 100], //每页显示多少条
        total: 200,
        layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
      },
      searchParams: {},
      header_data_list: [],
      propMap: {},
      obj_list: {},
      HeaderData: [],
      waybillIdNums: [],
      operation_type: 0,
      dynParams: {},
    };
  },
  components: {
    pagination,
    receiptDialog,
    customerCheckDetail,
    carrierCheckDetail,
    UploadLink,
    TableHeader,
    SettinUp,
  },
  mounted() {
    this.$store.commit("CHANGE_CHECK_TYPE", "");
    this.$store.commit("CHANGE_OPERATE_TYPE", "");
    this.displayOrdersData();
    this.getHandlersList();
    this.getReceiptBook();
    if (this.$store.getters.customerList.length === 0) {
      this.$store.dispatch("getCustomerList");
    }
    if (this.$store.getters.websiteList.length === 0) {
      this.$store.dispatch("getWebsiteList");
    }
    if (this.$store.getters.adminList.length === 0) {
      this.$store.dispatch("getAdminList");
    }
  },
  watch: {
    $route: {
      handler(newV, oldV) {
        if (this.$route.query.type == 0) {
          this.activeName = "0";
          this.displayOrders();
        } else if (this.$route.query.type == 1) {
          this.activeName = "1";
          this.displayOrders();
        } else if (this.$route.query.type == 2) {
          this.activeName = "2";
          this.displayOrders();
        } else if (this.$route.query.type == 3) {
          this.activeName = "3";
          this.displayOrders();
        } else if (this.$route.query.type == 4) {
          this.activeName = "4";
          this.displayOrders();
        }
      },
      immediate: true,
      deep: true,
    },
  },
  computed: {
    checkType() {
      return this.$store.getters.checkType;
    },
    headerId() {
      return "41";
    },
  },
  methods: {
    resultClickFn() {
      this.paginations.pageIndex = 1;
      this.paginations.pageSize = 20;
      this.$refs.TableHeaderList.childMethod();
    },
    objSettinUp() {
      this.displayOrders();
    },
    //接收vuex的数据
    async getCustomerList() {
      this.customerList = this.$store.getters.customerList;
    },
    async getBigAreaList() {
      this.bigAreaList = this.$store.getters.websiteList;
    },
    async getSalesList() {
      this.salesList = this.$store.getters.adminList;
    },
    async getHandlersList() {
      let result = await reqHandlersList({ branch_id: "1" });
      this.creatorList = result.data;
      setTimeout(() => {
        this.receiptSearchData.last_editor_id =
          JSON.parse(localStorage.getItem("user")).user_id * 1;
      }, 100);
    },
    async getReceiptBook() {
      let result2 = await reqReceiptBookList({
        body_belong: "0", //请求我方发票主体公司
      });
      if (result2.code === 10000) {
        this.company_invoice_book_list = result2.data;
      }
    },
    applyForReceipt() {
      this.dialogTableVisible = true;
      this.query_customer_Orders();
      //展开申请开票的抽屉
    },
    async rejectInvoice() {
      //审核不通过
      if (this.selectedOrders.length === 1) {
        let result = await reqAuditReceipt({
          id: this.selectedOrders[0],
          reviewer_id: JSON.parse(localStorage.getItem("user")).user_id + "",
          audit_time: timestamp10(new Date().getTime()),
          audit_result: "0", // 0审核不通过，1通过
        });
        if (result.code === 10000) {
          this.$message({
            type: "success",
            message: result.message,
          });
          this.displayOrders();
        } else {
          this.$message({
            type: "success",
            message: result.message,
          });
        }
      } else {
        this.$message({
          type: "error",
          message: "只能选择一个对账单进行操作",
        });
      }
    },
    async auditInvoice() {
      //审核通过
      if (this.selectedOrders.length === 1) {
        var param = {
          id: this.selectedDetails[0].id,
        };
        reqAuditReceipt(param).then((res) => {
          if (res.code == 10000) {
            this.displayOrders();
          }
        });
      } else {
        this.$message({
          type: "error",
          message: "只能选择一个对账单进行操作",
        });
      }
    },
    toAdoptReceipt() {
      Object.assign(
        this.$data.receiptReturnData,
        this.$options.data().receiptReturnData
      );
      if (this.selectedOrders.length === 1) {
        this.showReceiptReturn = true;
        this.receiptReturnData.actual_invoice_amount =
          this.selectedDetails[0].invoice_amount;
      } else {
        this.$message({
          type: "error",
          message: "只能选择一个对账单进行操作",
        });
      }
    },
    receiptSubmit(formList) {
      this.$refs[formList].validate((valid) => {
        if (valid) {
          //提交确认开票
          if (this.selectedOrders.length === 1) {
            var param = {
              ...this.receiptReturnData,
              id: this.selectedDetails[0].id,
              make_out_invoice_time: timestamp10(
                this.receiptReturnData.make_out_invoice_time
              ),
            };
            reqAdoptReceipt(param).then((result) => {
              if (result.code === 10000) {
                this.$message({
                  type: "success",
                  message: "开票成功",
                });
                this.showReceiptReturn = false;
                this.displayOrders();
              }
            });
          } else {
            this.$message({
              type: "error",
              message: "只能选择一个对账单进行操作",
            });
          }
        }
      });
    },
    async abolishReceipt() {
      //作废
      if (this.selectedOrders.length === 1) {
        let result = await reqCancelReceipt({
          id: this.selectedOrders[0],
        });
        if (result.code === 10000) {
          this.$message({
            type: "success",
            message: "作废成功",
          });
          this.displayOrders();
        } else {
          this.$message({
            type: "success",
            message: "作废成功",
          });
        }
      } else {
        this.$message({
          type: "error",
          message: "只能选择一个对账单进行操作",
        });
      }
    },
    async redFlushReceipt() {
      //红冲
      if (this.selectedOrders.length === 1) {
        let result = await reqRedFlushReceipt({
          id: this.selectedOrders[0],
        });
        if (result.code === 10000) {
          this.$message({
            type: "success",
            message: result.message,
          });
          this.displayOrders();
        } else {
          this.$message({
            type: "success",
            message: result.message,
          });
        }
      } else {
        this.$message({
          type: "error",
          message: "只能选择一个对账单进行操作",
        });
      }
    },
    //上传附件的函数
    beforeRemoveAttachment(file, fileList) {
      return this.$confirm("是否删除该附件");
    },
    handlePreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogImageVisible = true;
    },
    handleRemoveAttachment(file, fileList) {
      if (
        this.receiptReturnData.electronic_invoice_attachment.length > 0 &&
        this.receiptDisable != true
      ) {
        for (
          var i = 0;
          i < this.receiptReturnData.electronic_invoice_attachment.length;
          i++
        ) {
          if (
            this.receiptReturnData.electronic_invoice_attachment[i].uid ==
            file.uid
          ) {
            this.receiptReturnData.electronic_invoice_attachment.splice(i, 1);
          }
        }
      }
    },
    handleChangeAttachment(file, fileList, type) {
      this.fileList = fileList;
      var filelist = file.raw; //文件
      var filename = file.raw.uid + file.raw.name; //通过 uid和name组成文件的名字
      uploading(filelist, filename, type).then((result) => {
        var resname = result.name;
        this.ImportDataUrl = resname;
        var filehttp = "http://oss.dushisc.com/";
        this.receiptReturnData.electronic_invoice_attachment.push({
          name: filehttp + result.name,
          url: filehttp + result.name,
        });
      });
    },
    handleDownload(file) {
      const fileName = file.url;
      const elink = document.createElement("a");
      fileName && (elink.download = fileName);
      elink.style.display = "none";
      elink.href = fileName;
      elink.target = "_blank";
      document.body.appendChild(elink);
      elink.click();
      URL.revokeObjectURL(elink.href); // 释放URL 对象
      document.body.removeChild(elink);
    },
    displayOrders(setHeader = true) {
      //  0待审批 1审批中 2待开票 3已开票 4已拒绝 5已作废

      var status_data = [];
      if (this.activeName == 0) {
        status_data = [0, 5];
      } else if (this.activeName == 1) {
        status_data = [1];
      } else if (this.activeName == 2) {
        status_data = [2];
      } else if (this.activeName == 3) {
        status_data = [3,4];
      } else if (this.activeName == 4) {
        status_data = [6];
      }
      var param = {
        ...this.checkSearchData,
        page: this.paginations.pageIndex,
        page_size: this.paginations.pageSize,
        status_list: status_data,
        ...this.searchParams,
        header_id: this.headerId + "",
      };
      reqReceiptReturnList(param).then((res) => {
        if (res.code == 10000) {
          this.tableData1 = res.data.data || [];
          this.paginations.total = res.data.pagination.total;
          this.tableData1.unshift({});
          this.header_data_list = this.tableData1;
          if (setHeader) {
            this.HeaderData = res.data.item_list;
            this.Fntransformation(this.HeaderData);
          }
        }
      });
    },
    objheader(obj) {
      this.paginations.pageIndex = 1;
      this.searchParams = obj;
      this.displayOrders(false);
    },
    Fntransformation(obj) {
      const result = {};
      for (const prop in obj) {
        if (obj.hasOwnProperty(prop)) {
          if (obj[prop].send_name !== "") {
            result[obj[prop].name] = obj[prop].show_name;
          } else {
            result[obj[prop].name] = obj[prop].name;
          }
        }
      }
      this.propMap = result;
    },
    resettingData() {
      Object.assign(
        this.$data.checkSearchData,
        this.$options.data().checkSearchData
      );
      this.displayOrders();
    },
    handleClickEdit(row, operate) {
      if (
        row.invoice_detail.status === "4" &&
        row.invoice_detail.is_red_flush === "0"
      ) {
        this.$message({
          type: "error",
          message: "已红冲的发票可以修改发票信息",
        });
      } else {
        this.$store.commit("CHANGE_OPERATE_TYPE", operate);
        this.invoice_id = row.invoice_detail.id;
        this.$refs.receiptDialog.dialogVisible = true;
      }
    },
    viewReceiptInfo(row, type) {
      //查看开票详情
      this.receiptReturnData.make_out_invoice_time =
        row.invoice_detail.make_out_invoice_time * 1000;

      this.receiptReturnData.actual_invoice_amount =
        row.invoice_detail.actual_invoice_amount;
      this.receiptReturnData.electronic_invoice_attachment =
        row.invoice_detail.electronic_invoice_attachment;
      this.fileList = [
        {
          uid: "",
          url: row.invoice_detail.electronic_invoice_attachment,
        },
      ];
      this.showReceiptReturn = true;
      this.receiptDisable = true;
    },
    clickToDetail(row) {
      if (this.activeName === "0") {
        // this.$store.commit("GET_CHECK_DETAIL_ID", row.id);
        // this.type = 1 + "";
      } else {
        // this.$store.commit("GET_CHECK_DETAIL_ID", row.account_info.id);
        // this.type = 1 + "";
      }
      // this.$store.commit("CHANGE_CHECK_TYPE", "info");
    },
    handleSelectionChange(checked) {
      this.selectedOrders = checked.map((item) =>
        item.id ? item.id : item.invoice_detail.id
      );
      this.selectedDetails = checked;
      this.receiptReturnData.id = this.selectedOrders[0];
    },
    handleDeleteType(ids, val) {
      this.handleSelectionChange(val);
    },
    handleSizeChange1(val) {
      this.paginations.pageSize = val;
      this.displayOrders();
    },
    handleCurrentChange1(val) {
      this.paginations.pageIndex = val;
      this.displayOrders();
    },
    handleSizeChange2(val) {
      this.pageSize2 = val; //一页多少条
      this.displayOrders();
    },
    handleCurrentChange2(val) {
      this.pageNum2 = val; //第多少页
      this.displayOrders();
    },
    openUrl(file) {
      window.open(file.name);
    },

    // 申请开票查询
    query_customer_Orders() {
      var param = {
        ...this.query_customer,
        branch_id: this.query_customer.branch_id + "",
        start_time:
          this.query_customer.creationTimee !== null &&
          this.query_customer.creationTimee[0]
            ? String(parseInt(this.query_customer.creationTimee[0] / 1000))
            : "",
        end_time:
          this.query_customer.creationTimee !== null &&
          this.query_customer.creationTimee[1]
            ? String(parseInt(this.query_customer.creationTimee[1] / 1000))
            : "",
        page: this.query_customer.page + "",
        page_size: this.query_customer.page_size + "",
      };
      getCustomerCheckedList(param).then((res) => {
        if (res.code == 10000) {
          this.ordersList = res.data.data;
          this.alltotal = res.data.pagination.total * 1;
        }
      });
    },
    // 申请开票的重置
    query_customer_reset() {
      Object.assign(
        this.$data.query_customer,
        this.$options.data().query_customer
      );
      this.query_customer_Orders();
    },
    // 下一步页面跳转
    NewStatement() {
      if (this.idlist.length == 1) {
        this.$router.push({
          name: "receiptManageadd",
          query: {
            Type: 0,
            id: this.idlist[0].id,
            now_price: this.idlist[0].now_price,
            account_customer_id: this.idlist[0].account_customer_id,
            account_no: this.idlist[0].account_no,
            TageType: 0,
            customer_name: this.idlist[0].account_customer_name,
          },
        });
      } else {
        this.$message({
          type: "error",
          message: "只能选择一个对账单进行操作",
        });
      }
    },
    innerVisible_handle(val) {
      this.query_customer.page_size = val;
      this.query_customer_Orders();
    },
    innerVisible_Change(val) {
      this.query_customer.page = val;
      this.query_customer_Orders();
    },
    innerVisible_tionChange(val) {
      this.idlist = val;
    },
    invoice_apply_send_reviewwObj() {
      var param = {
        id: this.selectedDetails[0].id,
      };
      invoice_apply_send_revieww(param).then((res) => {
        if (res.code == 10000) {
          this.displayOrders();
        }
      });
    },
    handleClickDetail(value) {
      var invoice_body_belong = "";
      if (this.activeName == 0) {
        invoice_body_belong = 0;
      } else if (this.activeName == 1) {
        invoice_body_belong = 1;
      } else if (this.activeName == 2) {
        invoice_body_belong = 2;
      } else if (this.activeName == 3) {
        invoice_body_belong = 5;
      } else if (this.activeName == 4) {
        invoice_body_belong = 6;
      }
      this.$router.push({
        name: "receiptManageadd",
        query: {
          id: value.id,
          Type: 2,
          TageType: invoice_body_belong,
          // checkSearchData:this.checkSearchData,
        },
      });
    },
    handleClickEdit(value) {
      var invoice_body_belong = "";
      if (this.activeName == 0) {
        invoice_body_belong = 0;
      } else if (this.activeName == 1) {
        invoice_body_belong = 1;
      } else if (this.activeName == 2) {
        invoice_body_belong = 2;
      } else if (this.activeName == 3) {
        invoice_body_belong = 5;
      } else if (this.activeName == 4) {
        invoice_body_belong = 6;
      }
      this.$router.push({
        name: "receiptManageadd",
        query: {
          id: value.id,
          Type: 1,
          TageType: invoice_body_belong,
        },
      });
    },
    toAdoptReceiptDetail(val) {
      this.showReceiptReturn = true;
      this.receiptDisable = true;
      var param = {
        id: val.id,
      };
      invoice_apply_detail(param).then((res) => {
        this.receiptReturnData = res.data;
        this.receiptReturnData.make_out_invoice_time =
          res.data.make_out_invoice_time == 0
            ? ""
            : res.data.make_out_invoice_time * 1000;
      });
    },
    displayOrdersData() {
      // // console.log(this.activeName, "this.activeName")
      this.selectedOrders = [];
      if (this.activeName == 0) {
        this.$router.push(
          { name: "receiptManage", query: { Typedata: 0 } },
          () => {},
          () => {}
        );
        Object.assign(
          this.$data.checkSearchData,
          this.$options.data().checkSearchData
        );
        this.displayOrders();
      } else if (this.activeName == 1) {
        this.$router.push(
          { name: "receiptManage", query: { Typedata: 1 } },
          () => {},
          () => {}
        );
        Object.assign(
          this.$data.checkSearchData,
          this.$options.data().checkSearchData
        );
        this.displayOrders();
      } else if (this.activeName == 2) {
        this.$router.push(
          { name: "receiptManage", query: { Typedata: 2 } },
          () => {},
          () => {}
        );
        Object.assign(
          this.$data.checkSearchData,
          this.$options.data().checkSearchData
        );
        this.displayOrders();
      } else if (this.activeName == 3) {
        this.$router.push(
          { name: "receiptManage", query: { Typedata: 5 } },
          () => {},
          () => {}
        );
        Object.assign(
          this.$data.checkSearchData,
          this.$options.data().checkSearchData
        );
        this.displayOrders();
      } else if (this.activeName == 4) {
        this.$router.push(
          { name: "receiptManage", query: { Typedata: 6 } },
          () => {},
          () => {}
        );
        Object.assign(
          this.$data.checkSearchData,
          this.$options.data().checkSearchData
        );
        this.displayOrders();
      }
      // Object.assign(
      //   this.$data.checkSearchData,
      //   this.$options.data().checkSearchData
      // );
      // this.displayOrders();
    },
    deriveExprot() {
      var activeDate = [];
      if (this.activeName == 0) {
        activeDate = [0, 5];
      } else if (this.activeName == 1) {
        activeDate = [1];
      } else if (this.activeName == 2) {
        activeDate = [2];
      } else if (this.activeName == 3) {
        activeDate = [3];
      } else if (this.activeName == 4) {
        activeDate = [6];
      }
      var param = {
        apply_no: this.checkSearchData.apply_no,
        customer_id: this.checkSearchData.customer_id,
        ids: this.selectedOrders.map(Number),
        status_list: activeDate,
      };
      invoice_apply_list_export(param).then((res) => {
        if (res.code == 10000) {
          window.open("https://" + res.data.loaded_url);
          this.$message({
            type: "success",
            message: "导出成功",
          });
        }
      });
    },
    // 对账单号
    StatementNumber(val) {
      // dataPage 从0 开始
      this.$router.push({
        name: "shippingcustomer",
        query: { id: val, dataPage: 0 },
      });
    },
    // 删除发票
    invoice_apply_delete() {
      var param = {
        id: this.selectedDetails[0].id,
      };
      finance_invoice_apply_delete(param).then((res) => {
        if (res.code == 10000) {
          this.displayOrders();
        }
      });
    },
  },
};
</script>

<style lang="less" scoped>
// /deep/ .el-tabs__nav-wrap {
//   left: -154px;
// }
.shareContainer {
  padding: 10px 15px;
  background-color: #fff;

  .el-form-item--mini.el-form-item {
    margin-bottom: 10px;
  }

  .operation {
    height: 40px;

    .el-button {
      margin-left: 0px;
      margin-right: 10px;
    }

    ::v-deep .el-pagination {
      float: right;
      margin: 0px 0px 0px 20px;

      .el-input--mini .el-input__inner {
        height: 24px;
      }
    }
  }

  /deep/ .el-tabs--border-card > .el-tabs__content {
    padding: 0px;
  }

  .tab.el-tabs--border-card {
    border: none;
    box-shadow: none;

    .el-tabs__content {
      padding: 0;
      height: 40px;
    }
  }
}

.innerVisible_pagin {
  display: flex;
  justify-content: flex-end;
  margin: 0px 0px 10px 0px;
}

.innerVisible_button {
  text-align: center;
  margin: 10px 0px 0px 0px;
}
.actions {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  width: 100%;
  background-color: #fff;

  .el-button + .el-dropdown,
  .el-dropdown + .el-button {
    margin-left: 10px;
  }
}
</style>